package com.jacky;

import com.jacky.po.AbstractUser;
import com.jacky.service.IdentifyService;
import com.jacky.service.UserService;
import com.jacky.service.impl.IdentifyServiceImpl;
import com.jacky.service.impl.UserServiceImpl;
import com.sun.org.slf4j.internal.Logger;
import com.sun.org.slf4j.internal.LoggerFactory;

import java.util.Scanner;

/**
 * @Description: 启动入口
 * @author: Jacky
 * @date: 2021.10.12
 */
public class Main {

    public static void main(String[] args) {

        System.out.println("欢迎进入某某系统");
        Scanner input = new Scanner(System.in);
        UserService userService = new UserServiceImpl();
        IdentifyService identifyService = new IdentifyServiceImpl();
        i:while (true){
            System.out.println("请选择功能：");
            System.out.println("1.登录");
            System.out.println("2.注册");
            System.out.println("0.退出");
            String str = input.next();
            switch (str){
                case "1":
                    System.out.println("请选择你的身份：");
                    System.out.println("1.管理员");
                    System.out.println("2.普通访客");
                    String identityForLogin = input.next();
                    System.out.println("请输入你的账号：");
                    String userNameForLogin = input.next();
                    System.out.println("请输入你的密码：");
                    String passwordForLogin = input.next();
                    AbstractUser userForLogin = identifyService.identifyForLogin(userNameForLogin,passwordForLogin,identityForLogin);
                    boolean flagForLogin = userService.login(userForLogin);
                    if(flagForLogin){
                        System.out.println("登录成功");
                    } else {
                        System.out.println("身份或者账户或者密码存在错误，登录失败");
                    }
                    break;
                case "2":
                    System.out.println("用户注册");
                    System.out.println("请选择你的注册身份：");
                    System.out.println("1.管理员");
                    System.out.println("2.普通访客");
                    String identityForRegister = input.next();
                    System.out.println("请输入注册账号：");
                    String userNameForRegister = input.next();
                    System.out.println("请输入注册密码：");
                    String passwordForRegister = input.next();
                    AbstractUser userForRegister = identifyService.identifyForRegister(userNameForRegister,passwordForRegister,identityForRegister);
                    boolean flagForRegister = userService.register(userForRegister);
                    if (flagForRegister){
                        System.out.println("注册成功");
                    }else {
                        System.out.println("注册失败");
                    }
                    break;
                case "0":
                    System.out.println("再见~");
                    break i;
                default:
                    System.out.println("输入错误");
                    break;
            }
        }
    }
}
